/**
 * attr vuex
 * 属性模块
 */
const State = {
  cat: [], // 属性cat(通用全模块)
  prop: {}, // 属性规模分析的prop
  selectProps: [] // pool 属性池保存的选择结果
};

// getters
const Getters = {
  prop: state => state.prop,
  cat: state => state.cat,
  selectProps: state => state.selectProps
};

// mutations
const Mutations = {
  reset: state => {
    const s = {
      cat: [], // 属性cat(通用全模块)
      prop: {}, // 属性规模分析的prop
      selectProps: [] // pool 属性池保存的选择结果
    };
    Object.keys(s).forEach(key => {
      state[key] = s[key];
    });
  },
  SET_PROP: (state, prop) => {
    state.prop = { ...prop };
  },
  SET_CAT: (state, { cat, index }) => {
    // 如果数组长度大于index
    if (state.cat.length - 1 >= index) {
      state.cat = state.cat.slice(0, index);
    }
    state.cat.push(cat);
  },
  SET_SELECTPROPS: (state, select_props) => {
    state.selectProps = [...select_props];
  }
};
// actions
const Actions = {
  storeCat({ commit }, { cat, index }) {
    commit('SET_CAT', { cat, index });
  },
  storeProp({ commit }, prop) {
    commit('SET_PROP', prop);
  },
  storeSelectProps({ commit }, select_props) {
    commit('SET_SELECTPROPS', select_props);
  }
};

export default {
  namespaced: true,
  strict: true,
  state: State,
  getters: Getters,
  actions: Actions,
  mutations: Mutations
};
